const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const webpack = require('webpack');

module.exports = {
  // 入口
  entry: {
    main: './src/index.tsx'
  },
  // 出口
  output: {
    filename: 'js/[name]-[hash:5].js',
    path: path.join(__dirname, '/dist')
  },
  // 自动补全后缀
  resolve: {
    extensions: ['.tsx', '.ts', '.js']
  },
  module: {
    rules: [
      // 处理typescript
      {
        test: /\.tsx?$/,
        exclude: /node_modules/,
        use: {
          loader: 'ts-loader'
        }
      },
      // html处理--与 HtmlWebPackPlugin 冲突 故放弃

      //图片处理
      {
        test: /\.(png|jpg|jpeg|svg|gif)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              name: '[name]-[hash:5].[ext]',
              limit: 2048, // size <= 2KB
              outputPath: 'images/'
            }
          }
        ]
      }
    ]
  },
  plugins: [
    //文件清理
    new CleanWebpackPlugin()
  ]
};
